/**
 * @typedef ApproveBody
 * @property {string} articleId.required -文章id
 * @property {string} status.required -审核结果
 * @property {string} reason -审核不通过原因
 */

const express = require('express')
const router = express.Router()
const auth = require('@/middleware/auth.middleware')
const articleController = require('@/controllers/article.controller')

/**
 * 文章列表分页查询
 * @route GET /article
 * @summary 文章列表分页查询
 * @group 文章管理
 * @param {string} pageNo.query.required
 * @param {string} pageSize.query.required
 * @param {string} searchKeywords.query
 * @param {string} status.query
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @access article-manage-permission:btn:find
 * @security JWT
 */
router.get('/', auth(), articleController.findPage)

/**
 * 单个文章删除
 * @route DELETE /article
 * @summary 文章删除
 * @group 文章管理
 * @param {string} id.query.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @access article-manage-permission:btn:delete
 * @security JWT
 */
router.delete('/', auth(), articleController.deleteById)

/**
 * 文章审核
 * @route POST /article/approve
 * @summary 文章审核
 * @group 文章管理
 * @param {ApproveBody.model} ApproveBody.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @access article-manage-permission:btn:approve
 * @security JWT
 */
router.post('/approve', auth(), articleController.approveArticle)

/**
 * 文章重新审核
 * @route POST /article/reapprove
 * @summary 文章重新审核
 * @group 文章管理
 * @param {ApproveBody.model} ApproveBody.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @access article-manage-permission:btn:approve-again
 * @security JWT
 */
router.post('/reapprove', auth(), articleController.approveArticle)

module.exports = router
